package com.bw.controller;

import com.bw.Interceptor.PermissionConstants;
import com.bw.annontation.RequiredPermission;
import com.bw.annontation.Token;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author qpx
 * @description 产品管理
 * @date 2017/10/25
 * @since 1.0
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    private static final Logger log = LoggerFactory.getLogger(ProductController.class);

    /**
     * 产品列表
     *
     * @return
     */
    @RequestMapping("/list")
    @RequiredPermission(PermissionConstants.ADMIN_PRODUCT_LIST) // 权限注解
    public String list() {
         // 省略产品列表查询逻辑
        return "/product/list";
    }

    /**
     * 产品详情
     *
     * @return
     */
    @RequestMapping("/detail")
    @RequiredPermission(PermissionConstants.ADMIN_PRODUCT_DETAIL) // 权限注解
    public String detail() {
        // 省略查询产品详情的逻辑
        return "/product/edit";
    }

    /**
     * 删除产品
     *
     * @return
     */
    @RequestMapping("/delete")
    public String delete() {
        // 省略删除产品的逻辑
        return "/product/list";
    }

    /**
     * 新增产品
     * @return
     */
    @RequestMapping("/create")
    @Token(remove = true)
    @ResponseBody
    public String create(){
        System.out.println("------------");
        return "/product/list";
    }

    @Token(save = true)
    @RequestMapping("/savetoken")
    @ResponseBody
    public String getToken(HttpServletRequest request, HttpServletResponse response){
        return (String) request.getSession().getAttribute("token");
    }


 }